﻿Public Class Utilidades
    Public Shared Function FormatNumeroSrm(ByVal varExpr As Object, ByRef strFormat As String) As String
        Dim i As Short
        Dim strResult As String = ""
        Dim strExpr As String

        strExpr = Format$(varExpr, strFormat)

        For i = 1 To Len(strExpr)
            If IsNumeric(Mid(strExpr, i, 1)) Then
                strResult = strResult & Mid(strExpr, i, 1)
            End If
        Next

        Return strResult
    End Function

    Public Shared Function OpenADODBConnection(ByVal CadenaConexion As String) As ADODB.Connection
        Dim objConexion As ADODB.Connection = New ADODB.Connection

        objConexion.ConnectionString = CadenaConexion

        If objConexion.State <> ADODB.ObjectStateEnum.adStateOpen Then
            objConexion.Open()
        End If

        Return objConexion
    End Function

    Public Shared Sub OpenADODBConnection(ByVal CadenaConexion As String, ByRef objConexion As ADODB.Connection)
        If objConexion Is Nothing Then
            objConexion = New ADODB.Connection
            objConexion.ConnectionString = CadenaConexion
        End If

        If objConexion.State <> ADODB.ObjectStateEnum.adStateOpen Then
            objConexion.Open()
        End If
    End Sub

    Public Shared Sub OpenADODBConnection(ByRef objConexion As ADODB.Connection)
        If Not objConexion Is Nothing Then
            If objConexion.State <> ADODB.ObjectStateEnum.adStateOpen Then
                objConexion.Open()
            End If
        End If
    End Sub
End Class
